package org.hq.jsoup;

import com.hq.utils.jsoup.SihuHtml;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SpringBootTest
class SihuHtmlTest {
private SihuHtml sihuHtml = new SihuHtml();
    @Test
    void sihuMenuHome() {
        sihuHtml.SihuMenuHome();
// row col6 clearfix
    }
    @Test
    void rowcol6clearfix() {
        String uir="https://www.2e010b15.com/av/index.html";
        try {
            Document doc = Jsoup.connect(uir).get();
            // 定位 女优合集条目
            Elements itema = doc.select("div.row.col6.clearfix > dl > dt > a");
            // 遍历 女优合集条目
            for (Element item : itema){
                String imgNirou = item.select("img").first().attr("alt");
                String attr = item.attr("href");
                if (!imgNirou.equals("女优合集") && !attr.equals("/av/index.html")){
                    // 女优合集处理
                    System.out.println(imgNirou);
                    System.out.println(attr);
                }
            }

        } catch (IOException e) {

        }
    }












    @Test
    void baseb64() {
        // document.write(d('5aWz5LyY5ZCI6ZuG'));
        String var ="document.write(d('5aWz5LyY5ZCI6ZuG'));";
        try {
            // 非空字符串才进行解码
            // if (var == null && var.length() < 0) return null;
            // 查找匹配字符
            String findStrStart = "document.write";
            String findStrEnd = "'));";
            Pattern pattern = Pattern.compile(findStrStart);
            Matcher matcher = pattern.matcher(var);
            if (matcher.find()){
                System.out.println();
                var=var.substring(matcher.end()+4,var.indexOf(findStrEnd));
            }

            // 解码
            // byte[] base64Bytes = DatatypeConverter.parseBase64Binary(var);

            // byte[] 转 String
            String de=new String(Base64.getDecoder().decode(var), "utf-8");
            System.out.println(de);
        } catch (Exception e) {

        }


    }



    @Test
    void sihugroupItemCount() {
    }

    @Test
    void sihuHttpVideoItem() {
    }

    @Test
    void siHuVideoPaly() {
    }

    @Test
    void testSiHuVideoPaly() {
    }

    @Test
    void play() {
    }

    @Test
    void getUir() {
    }
}